<template>
    <div class="logincontainer">
        <div class="logintop">
            <img src="@/assets/images/loginbg.png" alt="" srcset="">
        </div>
        <div class="loginbox">
            <!--  @submit="onSubmit" -->
            <van-form class="loginboxform" @submit="onSubmit">
                <!-- <van-cell-group class="tl"> -->
                    <van-field v-model="form.username" label="" :rules="[{ required: true, message: '请填写用户名' }]" class="mb_12 " placeholder="请输入账号" />
                <!-- </van-cell-group> -->
                <!-- <van-cell-group class="tl"> -->
                    <van-field 
                        v-model="form.password" 
                        :type="showpsd?'':'password'" 
                        label="" 
                        :right-icon="showpsd?'eye-o':'closed-eye'"
                        :rules="[{ required: true, message: '请填写密码' },{pattern:/^.{6,18}$/, message:'密码长度必须为6-18个字符'}]" 
                        class="borderinput" 
                        placeholder="请输入密码"
                        @click-right-icon="showPassword" />
                <!-- </van-cell-group>   @click="onSubmit"-->
                <van-button class="loadbtn" native-type="submit">
                    <van-loading v-if='loading' type="spinner" size="16px" color="#fff" style="display:inline-block"/> 
                    <span class="logintext"> 登录 </span>
                </van-button>
                <div class="flexrowbetween bottomspan">
                    <span class="commhover" @click="goPage('/register')">新用户注册</span>
                    <span></span>
                    <!-- <span class="commhover" @click="goPage('/updatepwd')">修改密码</span> -->
                </div>
            </van-form>
        </div>
    </div>
</template>

<script>
import PageBody from './PageBody.vue';
import { Toast } from 'vant'
import Cookies from 'js-cookie'
export default {
  data() {
    return {
      loading:false,
      form:{
        account:"",
        password:''
      },
      showpsd:false,
    //   validator(val) {
    //   return /^.{5,20}$/.test(val);
    // },
    }
  },

  components:{
    PageBody
  },

  mounted() {
  },

  methods: {

    showPassword(){
        this.showpsd = !this.showpsd
    },

    goPage(page){
        this.$router.push({path:page})
    },

    onSubmit(){
        console.log('123123')
        this.loading = true;
        this.$store.dispatch('user/login',this.form).then(res=>{
            Cookies.set('username',this.form.account);
            Cookies.set('password',this.form.password);
            this.$router.push({ path: "/" });
            // }else{
            //     console.log('失败',res.msg);
            //     this.$toast(res.msg);
            // }
            this.loading = false;
        }).catch(e=>{
            this.loading = false;
        })
    },
  }
}
</script>
<style lang="scss">
.loginboxform{
    .van-cell{
        padding: 0;
        background-color: transparent;
    }
    .van-field__body{
        background-color: white;
        padding: 20px 32px;
        border-radius: 12px;
    }
    .van-field__control{
        // border: 1px solid #000;
    }
    .van-cell::after{
        border: 0;
    }
    .van-field__error-message{
        padding-left:32px;
    }
    .van-button::before{
        background-color:transparent;
        border: 0;
    }
}
</style>
<style lang="scss" scoped>
.logincontainer{
  width: 100%;
  height: 100%;
}
.logintop{
    // height: 370px;
    width: 100%;

    img{
        width: 100%;
    }
}
.loginbox{
    width: 100%;
    padding: 0 40px 40px;
    margin-top: 68px;
}
.loadbtn{
    margin-top: 60px;
    width: 100%;
    height: 80px;
    background: url('~@/assets/images/lgoinbg.png') center no-repeat ;
    background-size: contain;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 30px;
    border: 0;
}
.logintext{
    margin-top: -10px;
}
.bottomspan{
    padding: 32px 36px 0;
    span{
        font-size: 28px;
    }
}
</style>
